package test;

import org.junit.Test;

public class Manipulation {

	@Test
	public void testManipulateEquation() {

		String equation = "y = ((x+2)/6)";

		char[] charArray = equation.toCharArray();

		double result = 4; // é o que veio

		String temp = "";

		for (int i = 0; i < charArray.length; i++) {

			if (charArray[i] == '+') {
				temp = equation.substring(i + 1);
				result = result
						+ Integer
								.parseInt(temp.substring(0, temp.indexOf(")")));
			} else if (charArray[i] == '-') {
				temp = equation.substring(i + 1);
				result = result
						- Integer
								.parseInt(temp.substring(0, temp.indexOf(")")));
			} else if (charArray[i] == '*') {
				temp = equation.substring(i + 1);
				result = result
						* Integer
								.parseInt(temp.substring(0, temp.indexOf(")")));
			} else if (charArray[i] == '/') {
				System.out.println(i);
				System.out.println(equation);
				temp = equation.substring(i + 1);
				result = result
						/ Integer
								.parseInt(temp.substring(0, temp.indexOf(")")));
			}

		}

		System.out.println(result);

	}
}
